

#include "cocos2d.h"
#include "Box2D/Box2D.h"

#include "Hole.h"
#include "CmnDef.h"

using namespace cocos2d;

Hole::Hole() : m_pBody(NULL)
{

}

void Hole::setPhysicsBody(b2Body * body)
{
    m_pBody = body;
}

// this method will only get called if the sprite is batched.
// return YES if the physics values (angles, position ) changed
// If you return NO, then nodeToParentTransform won't be called.
bool Hole::isDirty(void)
{
    return true;
}

// returns the transform matrix according the Chipmunk Body values
CCAffineTransform Hole::nodeToParentTransform(void)
{
    b2Vec2 pos  = m_pBody->GetPosition();

    float x = pos.x *PHYSICS_WORLD_SCALE_RATE;
    float y = pos.y *PHYSICS_WORLD_SCALE_RATE;

    if ( isIgnoreAnchorPointForPosition() ) {
        x += m_tAnchorPointInPoints.x;
        y += m_tAnchorPointInPoints.y;
    }

    // Make matrix
    float radians = m_pBody->GetAngle();
    float c = cosf(radians);
    float s = sinf(radians);

    if( ! m_tAnchorPointInPoints.equals(CCPointZero) ){
        x += c*-m_tAnchorPointInPoints.x + -s*-m_tAnchorPointInPoints.y;
        y += s*-m_tAnchorPointInPoints.x + c*-m_tAnchorPointInPoints.y;
    }

    // Rot, Translate Matrix
    m_tTransform = CCAffineTransformMake( c,  s,
        -s,    c,
        x,    y);


	//m_tTransform = CCAffineTransformScale(m_tTransform, this->getScaleX(), this->getScaleY());

    return m_tTransform;
}




